<?php

/**
 * This is the model class for table "tb_perito".
 *
 * The followings are the available columns in table 'tb_perito':
 * @property integer $ID_PERITO
 * @property string $NOME_PERITO
 * @property string $TELEFONE_PERITO
 * @property integer $TB_REGULADORA_ID_REGULADORA
 *
 * The followings are the available model relations:
 * @property TbReguladora $tBREGULADORAIDREGULADORA
 */
class Perito extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Perito the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_perito';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('NOME_PERITO, TELEFONE_PERITO, TB_REGULADORA_ID_REGULADORA', 'required'),
			array('TB_REGULADORA_ID_REGULADORA', 'numerical', 'integerOnly'=>true),
			array('NOME_PERITO', 'length', 'max'=>100),
			array('TELEFONE_PERITO', 'length', 'max'=>15),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_PERITO, NOME_PERITO, TELEFONE_PERITO, TB_REGULADORA_ID_REGULADORA', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'Reguladora' => array(self::BELONGS_TO, 'Reguladora', 'TB_REGULADORA_ID_REGULADORA'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_PERITO' => 'Id Perito',
			'NOME_PERITO' => 'Nome',
			'TELEFONE_PERITO' => 'Telefone',
			'TB_REGULADORA_ID_REGULADORA' => 'Reguladora',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_PERITO',$this->ID_PERITO);
		$criteria->compare('NOME_PERITO',$this->NOME_PERITO,true);
		$criteria->compare('TELEFONE_PERITO',$this->TELEFONE_PERITO,true);
		$criteria->compare('TB_REGULADORA_ID_REGULADORA',$this->TB_REGULADORA_ID_REGULADORA);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
		
	//traz lista de reguladora para dropDown
	public function getReguladoraOptions(){

	    return CHtml::listData(Reguladora::model()->findAll(),'ID_REGULADORA','NOME_REGULADORA');
	
	}
		
}